#include "SimpleMoveController.h"
#include "global/GlobalDefine.h"

SimpleMoveController::SimpleMoveController(){
	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	m_speed = SPEED_Rocket;
	preY = visibleSize.width/2;
}

SimpleMoveController::~SimpleMoveController(){
	
}

SimpleMoveController* SimpleMoveController::create(Entity* entity){
	SimpleMoveController* simpleMoveController = new SimpleMoveController();

	if(simpleMoveController && simpleMoveController->init(entity)){
		simpleMoveController->autorelease();

	} else{
		CC_SAFE_DELETE(simpleMoveController);
		simpleMoveController = NULL;
	}

	return simpleMoveController;
}

bool SimpleMoveController::init(Entity* entity){
	bool bRet = false;
	do{
		CC_BREAK_IF(!BaseMoveController::init(entity));

		this->schedule(schedule_selector(SimpleMoveController::moveUp));
		bRet = true;
	}while(0);

	return bRet;
}

void SimpleMoveController::moveUp(float dt){
	if(m_entity != NULL){
		CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();

		float curY = m_entity->getPositionY()+m_speed;
		m_entity->setPositionY(curY);

		if(curY > preY){
			float moveLen = curY - preY;
			CCString* moveStr = CCString::createWithFormat("%f",moveLen);
			NOTIFY->postNotification(BG_MOVE_MSG,moveStr);
			preY = curY;
		}
	}
}